<template>
	<view class="lineUp">
		<view style="width: 100%" class="top-bar" v-if="list.length>0">
			<scroll-view class="" style="width: 100%;white-space: nowrap;" scroll-x="true">
				<view class="flex">
					<view class="item" v-for="(item,index) in list" :key="index" @click="active(item,index)">
						<view class="text">
							{{item.name}}
						</view>
						<view class="line" v-if="current==index"></view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="content" v-if="queueList.length>0">
			<scroll-view class="" style="width: 100%;height:91vh;" scroll-y="true">
				<view class="items" v-for="(item,index) in queueList" :key="index">
					<view class="title">
						大约候诊时间{{item.waitTime}}分
						<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="nums">
						当前<text class="blur">{{item.queueNownum}}</text>号|前面候诊<text
							class="blur">{{item.queueWaitnum}}</text>位
					</view>
					<view class="time">
						<text class="left">就诊人</text>
						<text>{{name}}</text>
					</view>
					<view class="time">
						<text class="left">就诊科室</text>
						<text>{{item.doctorName}}|{{item.departmentName}}|{{item.doctorTitle}}</text>
					</view>
					<!-- <view class="time">
					<text class="left">地点</text>
					<text>2号楼4层C区402诊室<text class="navigation">查看路线</text></text>
				</view> -->
				</view>
				<!-- <view class="items">
				<view class="title">
					<text>
						甲状腺彩超
						<text class="red">已过号，已为您重新排队</text>
					</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="nums">
					<text class="red">52</text>号|前面候诊<text class="red">2</text>位
				</view>
				<view class="time">
					<text class="left">就诊人</text>
					<text>罗伟，男，32岁</text>
				</view>
				<view class="time">
					<text class="left">就科室</text>
					<text>李医生|心脏内科|主治医师</text>
				</view>
				<view class="time">
					<text class="left">地点</text>
					<text>2号楼4层C区402诊室<text class="navigation">查看路线</text></text>
				</view>
			</view> -->
			</scroll-view>
		</view>
		<view class="noCard" v-if="list.length==0 || queueList.length == 0">
			<view class="images">
				<img src="@/static/images/noCard.png" alt="">
				<view>
					暂未查询到信息
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getWaitInfo,
		getPatientBaseList
	} from '@/api/card/index.js'
	export default {
		data() {
			return {
				list: [],
				current: 0,
				name: '',
				cardNum: '',
				idNum: '',
				waitTime: "",
				queueList: []
			}
		},
		onLoad() {
			this.getPatientList()
		},
		onPullDownRefresh() {
			this.getList()
		},
		methods: {
			active(item, index) {
				this.current = index
				this.name = item.name
				this.cardNum = item.cardNum
				this.idNum = item.idNum
				this.getList()
			},
			getPatientList() {
				let openid = uni.getStorageSync('openid') || ''
				getPatientBaseList({
					hospitalCode: JSON.parse(uni.getStorageSync('hospital')).hospitalCode,
					openId: openid
				}).then(res => {
					if (res.code == 200 && res.rows.length > 0) {
						this.list = []
						res.rows.forEach(item => {
							this.list.push({
								name: item.name,
								cardNum: item.cardNum,
								idNum: item.idNum
							})
						})
						this.name = this.list[0].name
						this.cardNum = this.list[0].cardNum
						this.idNum = this.list[0].idNum
						this.getList()
					}
				})
			},
			getList() {
				let params = {
					cardNum: this.cardNum,
					idNum: this.idNum,
					name: this.name
				}
				getWaitInfo(params).then(res => {
					//数据请求完成之后停止下拉刷新
					uni.stopPullDownRefresh();
					console.log(res)
					if (res.code == 200) {
						this.queueList = res.data || 0
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: rgb(245, 245, 245);
	}

	.lineUp {
		height: 100vh;
		overflow-y: auto;
	}

	.noCard {
		width: 100%;
		text-align: center;
		color: #666666;

		.images {
			width: 100%;
			margin-bottom: 20px;
			color: #666666;

			img {
				width: 55%;
				text-align: center;
			}
		}
	}

	.top-bar {
		background-color: #fff;
		padding: 10px;

		.item {
			display: flex;
			align-items: center;
			flex-direction: column;
			margin-right: 10px;
			font-size: 30rpx;

			.line {
				width: 70rpx;
				height: 3px;
				background-color: #4D8EFF;
				border-radius: 3px;
			}

			.text {
				padding: 10rpx;
			}
		}
	}

	.content {
		background-color: rgb(245, 245, 245);
		padding: 24rpx;

		.items {
			background-color: #fff;
			border-radius: 8px;
			margin-bottom: 24rpx;
			padding-bottom: 12rpx;

			.title {
				padding: 24rpx;
				display: flex;
				font-size: 32rpx;
				font-weight: 600;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1px solid #eee;

				.red {
					font-size: 24rpx;
					color: #FF3240;
					display: inline-block;
					margin-left: 20rpx;
				}
			}

			.nums {
				padding: 30rpx 0;
				text-align: center;
				font-size: 36rpx;

				.blur {
					color: #4D8EFF;
					margin: 0 6rpx;
				}

				.red {
					color: #FF3240;
					margin: 0 6rpx;
				}
			}

			.time {
				display: flex;
				justify-content: space-between;
				padding: 12rpx 24rpx;
				font-size: 28rpx;

				.left {
					color: #999;
					width: 130rpx;
				}

				.navigation {
					font-size: 12rpx;
					color: #4D8EFF;
					display: inline-block;
					margin-left: 10px;
				}
			}
		}
	}
</style>